﻿using Commission.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Commission.ViewModels
{
    /**
     * Chứa các loại tiền của TransactionHistory
     */
    public class TransactionHistorySum
    {
        private decimal amount80Per = new decimal(0.8);
        private decimal amount20Per = new decimal(0.2);

        public Customer Customer { get; set; }

        public AccountType AccountType { get; set; }

        public DateTime AccountDate { get; set; }

        // date from của đk search
        public string DateFrom { get; set; }

        // date to của đk search
        public string DateTo { get; set; }

        public decimal  DirectAmount { get; set; }

        public string DisplayDirectAmount
        {
            get
            {
                return string.Format("{0:#,0}", this.DirectAmount * amount80Per)
                    + " / " + string.Format("{0:#,0}", this.DirectAmount * amount20Per);
            }
        }

        public decimal  RollupAmount { get; set; }

        public string DisplayRollupAmount
        {
            get
            {
                return string.Format("{0:#,0}", this.RollupAmount * amount80Per)
                    + " / " + string.Format("{0:#,0}", this.RollupAmount * amount20Per);
            }
        }

        public decimal  OnlineAmount { get; set; }

        public string DisplayOnlineAmount
        {
            get
            {
                return string.Format("{0:#,0}", this.OnlineAmount * amount80Per)
                    + " / " + string.Format("{0:#,0}", this.OnlineAmount * amount20Per);
            }
        }

        public decimal  PairingAmount { get; set; }

        public string DisplayPairingAmount
        {
            get
            {
                return string.Format("{0:#,0}", this.PairingAmount * amount80Per)
                    + " / " + string.Format("{0:#,0}", this.PairingAmount * amount20Per);
            }
        }

        public decimal  MatchingAmount { get; set; }

        public string DisplayMatchingAmount
        {
            get
            {
                return string.Format("{0:#,0}", this.MatchingAmount * amount80Per)
                    + " / " + string.Format("{0:#,0}", this.MatchingAmount * amount20Per);
            }
        }

        public decimal UsedAmount
        {
            get {
                return UsedAmount80 + UsedAmount20;
            }
        }

        public decimal UsedAmount80 { get; set; }

        public decimal UsedAmount20 { get; set; }

        public string DisplayUsedAmount
        {
            get
            {
                /*
                if (AccountType == Models.AccountType.Active)
                {
                    return string.Format("{0:#,0}", decimal.Zero)
                        + " / " + string.Format("{0:#,0}", this.UsedAmount);
                }
                else
                {
                    return string.Format("{0:#,0}", this.UsedAmount)
                        + " / " + string.Format("{0:#,0}", decimal.Zero);
                }
                 */

                return string.Format("{0:#,0}", this.UsedAmount80)
                        + " / " + string.Format("{0:#,0}", this.UsedAmount20);
            }
        }

        public decimal TotalAmount { get; set; }

        public decimal TotalAmount80
        {
            get
            {
                decimal amount80 = DirectAmount * amount80Per
                    + RollupAmount * amount80Per
                    + OnlineAmount * amount80Per
                    + PairingAmount * amount80Per
                    + MatchingAmount * amount80Per;
                amount80 = amount80 + UsedAmount80;

                return amount80;
            }
        }

        public decimal TotalAmount20
        {
            get
            {
                decimal amount20 = (DirectAmount
                    + RollupAmount
                    + OnlineAmount
                    + PairingAmount
                    + MatchingAmount) * amount20Per + UsedAmount20;

                return amount20;
            }
        }

        public string DisplayTotalAmount
        {
            get
            {
                decimal amount80 = DirectAmount * amount80Per
                    + RollupAmount * amount80Per
                    + OnlineAmount * amount80Per
                    + PairingAmount * amount80Per
                    + MatchingAmount * amount80Per;
                amount80 = amount80 + UsedAmount80;

                decimal amount20 = (DirectAmount
                    + RollupAmount
                    + OnlineAmount
                    + PairingAmount
                    + MatchingAmount) * amount20Per + UsedAmount20;

                return string.Format("{0:#,0}", amount80)
                    + " / " + string.Format("{0:#,0}", amount20);
            }
        }

        // 80 toan bo thoi gian
        public decimal Amount80 { get; set; }

        // 20 toan bo thoi gian
        public decimal Amount20 { get; set; }

        public string AmountDetail
        {
            get
            {
                return string.Format("{0:#,0}", this.Amount80) 
                    + " / " + string.Format("{0:#,0}", this.Amount20);
            }
        }

        // so tien tich luy
        public decimal CumulativeAmount { get; set; }
    }
}